package com.laxcen.service.impl;

import com.laxcen.mapper.PermissionMapper;
import com.laxcen.model.Resources;
import com.laxcen.service.PermissionService;
import com.laxcen.util.CoreConst;
import com.laxcen.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;
/**
 * @version V1.0
 * @date 2018年7月11日
 * @author superzheng
 */
@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public Set<String> findPermsByUserId(String userId) {
        return permissionMapper.findPermsByUserId(userId);
    }

    @Override
    public List<Resources> selectAll(Integer status) {
        return permissionMapper.selectAllPerms(status);
    }

    @Override
    public List<Resources> selectAllMenuName(Integer status) {
        return permissionMapper.selectAllMenuName(status);
    }

    @Override
    public List<Resources> selectMenuByUserId(String userId) {
        return permissionMapper.selectMenuByUserId(userId);
    }

    @Override
    public int insert(Resources resources) {
        Date date = new Date();
        resources.setPermissionId(UUIDUtil.getUniqueIdByUUId());
        resources.setStatus(CoreConst.STATUS_VALID);
        resources.setCreateTime(date);
        resources.setUpdateTime(date);
        return permissionMapper.insert(resources);
    }

    @Override
    public int updateStatus(String  permissionId,Integer status) {
        return permissionMapper.updateStatusByPermissionId(permissionId,status);
    }

    @Override
    public Resources findByPermissionId(String permissionId) {
        return permissionMapper.selectByPermissionId(permissionId);
    }

    @Override
    public Resources findById(Integer id) {
        Resources resources = new Resources();
        resources.setId(id);
        return permissionMapper.selectByPrimaryKey(resources);
    }

    @Override
    public int updateByPermissionId(Resources resources) {
        return permissionMapper.updateByPermissionId(resources);
    }

    @Override
    public int selectSubPermsByPermissionId(String permissionId) {
        return permissionMapper.selectSubPermsByPermissionId(permissionId);
    }
}
